package com.qingke.console;

import java.util.Scanner;

public class Console {
private static Scanner sc = new Scanner(System.in);
	
	public static String askInput(String input){
		String in = null;
		while(true){
			System.out.print(input + " > ");
			 in = sc.nextLine();
			 
			 if(!in.trim().equals("") && in!=null){
				 break;
			 }
			 System.out.println("Please insert a non-null value!");
		}
		return in;
	}
	
	public static int askInputInt(String input){
		String s = null;
		int value = -1;
			while(true){
				s = askInput(input);
				try{
					 value = Integer.valueOf(s);
				}catch(NumberFormatException e){
					System.out.println("Please insert a number!");
				}
				
				if(value!=-1){
					break;
				}
			}
		return value;
	}
	
	public static double askInputDouble(String input){
		String s = null;
		double value = -1;
			while(true){
				s = askInput(input);
				try{
					 value = Double.valueOf(s);
				}catch(NumberFormatException e){
					System.out.println("Please insert a number!");
				}
				
				if(value!=-1){
					break;
				}
			}
		return value;
	}
	
	public static void exit(){
		System.out.println("Bye-bye");
		System.exit(0);
	}
}
